using System;
using System.Collections.Generic;
using System.IdentityModel.Selectors;
using System.Security.Cryptography.X509Certificates;

namespace NHServices.Model
{
    public class CustomCertificateValidator : X509CertificateValidator
    {
        public CustomCertificateValidator()
        {
            ValidCertificates = new List<X509Certificate2>();
        }

        public CustomCertificateValidator(IEnumerable<X509Certificate2> validCertificates)
        {
            ValidCertificates = new List<X509Certificate2>(validCertificates);
        }

        public IList<X509Certificate2> ValidCertificates { get; set; }

        public override void Validate(X509Certificate2 certificate)
        {
            if (certificate == null)
                throw new ArgumentNullException("certificate");

            foreach (X509Certificate2 cert in ValidCertificates)
            {
                if (cert.Equals(certificate))
                    return;
            }

            PeerOrChainTrust.Validate(certificate);
        }
    }
}